#include "game.h"


static location_t tplay_game_speed_X_Y = {.iX = 0,  .iY = 0};
static playgame_obstacle_t obstacles[2] = {{JULI+100,70,75,1},{JULI+296,41,95,1}};

static uint8_t ys_play_flag = 1;
static ice_block_iY_t ice_block_iY[2]={{0,0,0,191+JULI + 196*ICE_NUM},{0,0,0,191+196+JULI+ 196*ICE_NUM}};
//====================================================================================================
int8_t layer_3_location_iY[3]={40,85,65};//68  106  198  //ok
int8_t layer_3_location_iX[3]={40,40,40};//68  106  198  //ok
static arm_2d_location_t layer_3_location[3]={{0,30},{98,50},{156+98,70}};//ok
static uint8_t layer_3_nums[] = {0,1,2};//01234  //ok
static int16_t layer_3_iX = 0;//ok

static arm_2d_location_t layer_2_location[6]={{0,202-79},{49,202-64},{49+56,202-70},{49+117,202-90},{49+117+73,202-74},{49+117+99,202-73}};//
static int16_t layer_2_iX = 0;

const int8_t layer_1_location_add_iX[6]={40,20,21,13,30,36};
 int8_t layer_1_location_add_iY[6]={40,20,21,13,30,36};
static int16_t layer_1_location_iX[8]={10,70,100,130,160,191,222,260};
static arm_2d_location_t layer_1_location[8]={{10,203-17},{70,203-11},{100,203-7},{130,203-11},{160,203-21},{191,203-7},{242,203-10},{280,203-8}};
static uint8_t layer_1_nums[8] = {0,2,3,2,1,3,5,4};//48  18  19  11  24  26
																									 //17  21  11  7   8   10 
static arm_2d_location_t layer_01_location[]={{0,202},{50,202},{100,202},{150,202},{200,202},{250,202}};




typedef struct {
		
		arm_2d_location_t *ptLocation;
		const arm_2d_tile_t *ptTiles;
		int16_t offect_iX;
		uint8_t speed_iX;
		uint8_t Align_Bottom_iY;
		uint8_t tiles_nums;
		uint8_t for_num;
		uint8_t layer_level;
		uint8_t *ptRandom_tile_nums;
		arm_2d_region_t FillRegion;
		const int8_t *ptTiles_iY_offect;
		const int8_t *ptTiles_iX_offect;
		union {
				struct {						
						uint8_t bIsAlign_Bottom : 1;
						uint8_t bIsFill_Tile    : 1;
						uint8_t                 : 6;
				}uflag;
				uint8_t flag;
		};
}layer_t;

layer_t layers[4]={
	{
			.offect_iX = 0,
			.ptLocation = layer_3_location,
			.ptTiles = c_tile33,
			.tiles_nums = 3,
			.for_num = 3,
			.Align_Bottom_iY = 202,
			.speed_iX = 1,
			.layer_level = 4,
			.ptRandom_tile_nums = layer_3_nums,
			.ptTiles_iY_offect = layer_3_location_iY,
			.ptTiles_iX_offect = layer_3_location_iX,
			.uflag={
					
					.bIsAlign_Bottom = 0,
					.bIsFill_Tile = 0,
			},
	},
	{
			.offect_iX = 0,
			.ptLocation = layer_2_location,			
			.ptTiles = c_tileTree,
			//.tiles_nums = 6,
			//.for_num = 6,
			//.Align_Bottom_iY = 202,
			.speed_iX = 3,
			.layer_level = 2,
			.FillRegion={
					.tLocation = {.iX = 0,.iY = 202-90,},
					.tSize = {.iWidth = 240,.iHeight = 90,},			 					
			},
			.uflag={					
					.bIsAlign_Bottom = 0,
					.bIsFill_Tile = 1,
			},
	},
	{//xia bian
			.offect_iX = 0,
			.ptLocation = layer_01_location,
			.ptTiles = c_tile011,
			//.tiles_nums = 6,
			//.for_num = 6,
			//.Align_Bottom_iY = 203,
			.speed_iX = 6,
			.layer_level = 2,
			//.ptRandom_tile_nums = layer_1_nums,
			//.ptTiles_iY_offect = layer_1_location_add_iY,
			//.ptTiles_iX_offect = layer_1_location_add_iX,
			.FillRegion={
					.tLocation = {.iX = 0,.iY = 202,},
					.tSize = {.iWidth = 240,.iHeight = 38,},			 					
			},
			.uflag={					
					.bIsAlign_Bottom = 0,
					.bIsFill_Tile = 1,
			},
	},
	{//shi tou hua  cao
			.offect_iX = 0,
			.ptLocation = layer_1_location,
			.ptTiles = c_tile11,
			.tiles_nums = 6,
			.for_num = 8,
			.Align_Bottom_iY = 203,
			.speed_iX = 6,
			.layer_level = 2,
			.ptRandom_tile_nums = layer_1_nums,
			.ptTiles_iY_offect = layer_1_location_add_iY,
			.ptTiles_iX_offect = layer_1_location_add_iX,
			.uflag={					
					.bIsAlign_Bottom = 1,
					.bIsFill_Tile = 0,
			},
	},		
		
};

static int16_t layer_1_iX=0;

void paly_game_gui_refresh(const arm_2d_tile_t *ptTile, bool bIsNewFrame){
		arm_2d_region_t tBox = {
        .tLocation = {0,0},
        .tSize = {240,240-90},
    };
		static uint8_t sPeopleRun = 0;					
				
		arm_2d_rgb16_fill_colour(ptTile, &tBox, BACKGROUND_COLOR);
		//arm_2d_rgb16_fill_colour(ptTile, NULL, 0x0000);
		for(uint8_t y = 0; y < 4; y++){
				layer_t *ptItem = &layers[y];
				if(bIsNewFrame){
						if(ptItem->layer_level==1){
								if(ys_play_flag)
								ptItem->offect_iX += ptItem->speed_iX;
						}
						else if(((tplay_game_speed_X_Y.iX>>1) % ptItem->layer_level) == 1){
								if(ys_play_flag)
								ptItem->offect_iX += ptItem->speed_iX;
						}
				}
				if(ptItem->uflag.bIsFill_Tile){
						
						arm_2d_tile_t tChildTile;
						arm_2d_tile_generate_child(ptTile, &ptItem->FillRegion, &tChildTile, false);
					
						tBox.tLocation.iX = ptItem->ptLocation[0].iX - ptItem->offect_iX;								
						tBox.tLocation.iY = 0;							
						tBox.tSize.iWidth = 240-tBox.tLocation.iX;
						tBox.tSize.iHeight= ptItem->ptTiles[0].tRegion.tSize.iHeight;	
										
						arm_2d_rgb16_tile_copy_with_colour_masking( &ptItem->ptTiles[0], 
												&tChildTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_FILL);
						if(tBox.tLocation.iX < (-ptItem->ptTiles[0].tRegion.tSize.iWidth)){
								ptItem->ptLocation[0].iX -= ptItem->offect_iX;
								ptItem->offect_iX = 0;
						}
						continue;
				}
				
				for(uint8_t i = 0;i < ptItem->for_num; i++){
						uint8_t index = i;
						tBox.tLocation.iX = ptItem->ptLocation[i].iX - ptItem->offect_iX;
						if(tBox.tLocation.iX > 240){
								continue;
						}
						
						index = ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums;
						
						tBox.tSize.iWidth = ptItem->ptTiles[index].tRegion.tSize.iWidth;
						if(tBox.tLocation.iX <= (-tBox.tSize.iWidth)){
								
								index = (i+ptItem->for_num-1)%ptItem->for_num;
								ptItem->ptRandom_tile_nums[i] = myrand()%(ptItem->tiles_nums*2-1);//layer_3_nums[i] = myrand()%5;
							
								ptItem->ptLocation[i].iX =  ptItem->ptTiles_iX_offect[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums] 
																						+ (myrand()&0x1f) //myrand()%20 
																						+ ptItem->ptLocation[index].iX 
																						+ ptItem->ptTiles[ptItem->ptRandom_tile_nums[index%ptItem->tiles_nums]].tRegion.tSize.iWidth;
								ptItem->ptLocation[i].iY =  (myrand()&0xf) 
																						+ ptItem->ptTiles_iY_offect[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums];		
								
								
								if(ptItem->uflag.bIsAlign_Bottom){										
										ptItem->ptLocation[i].iY = ptItem->Align_Bottom_iY - ptItem->ptTiles[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums].tRegion.tSize.iHeight;										
								}
								for(uint8_t x = 0; x < ptItem->for_num; x++){
										ptItem->ptLocation[x].iX -= ptItem->offect_iX;
								}
								ptItem->offect_iX = 0;
								
								continue;
						}
						
						tBox.tLocation.iY = ptItem->ptLocation[i].iY ;
						tBox.tSize.iHeight= ptItem->ptTiles[index].tRegion.tSize.iHeight; 
						arm_2d_rgb16_tile_copy_with_colour_masking(  &ptItem->ptTiles[index], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
						
				}
				if(y == 0){
						tBox.tLocation.iX = 0;		
						tBox.tLocation.iY = 0;		
						tBox.tSize.iWidth = 240;
						tBox.tSize.iHeight= 240-90;	
						//arm_2d_rgb16_fill_colour(ptTile, &tBox, BACKGROUND_COLOR);
						arm_2d_rgb565_fill_colour_with_alpha(   
								ptTile, 
								&tBox, 
								(arm_2d_color_rgb565_t){BACKGROUND_COLOR}, 
								68);
				}
				
		}
		
		
		
		//======1====================================================
		do{
				static arm_2d_tile_t s_child_tilePipe = {
						.tRegion = {
							.tSize = {
								.iWidth = 26,
								.iHeight = 90,
							},
						},       
						.tInfo = {
								.bIsRoot = false,
								.bDerivedResource = true,
								.bHasEnforcedColour = true,
								.tColourInfo = {
										.chScheme = ARM_2D_COLOUR_RGB565,
								},
							},             
							.ptParent = (arm_2d_tile_t *)&c_tilePipe,
				};
				
				if(((tplay_game_speed_X_Y.iX>>1) % 2) == 1){
						if(ys_play_flag && bIsNewFrame){
								layer_1_iX+=6;
						}
				}
				//static playgame_obstacle_t obstacles[2] = {{500+100,70,75,1},{500+276,41,95,1}};
			
				for(uint8_t i = 0; i < 2; i++){
						tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;	
						#if DISAPPEAR
						if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){												
								if((tBox.tLocation.iX < - 26) || (tBox.tLocation.iX >= 240)){
										continue;
								}
								
						}
						#endif
						
						tBox.tSize.iWidth = 26;
						if(tBox.tLocation.iX < - tBox.tSize.iWidth){
								obstacles[i].iX = obstacles[i].iX+196 * 2;
								obstacles[i].iHight = 26 + (myrand()&0x3f);
								obstacles[i].iGap = 70 +  (myrand()&0x1f);
								continue;
						}
						
						
						//==leaf====
						
						tBox.tLocation.iY = 0;
						tBox.tSize.iWidth = 26;
						tBox.tSize.iHeight= obstacles[i].iHight;	
						//tBox.tSize.iHeight= 90;
						
						s_child_tilePipe.tRegion.tSize.iHeight = tBox.tSize.iHeight;
						//s_child_tilePipe.tRegion.tSize.iHeight = 90;
						
						arm_2d_rgb16_tile_copy_with_colour_masking( &s_child_tilePipe, 
																ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_Y_MIRROR);
														//ARM_2D_CP_MODE_COPY);
						
						
						
						tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;		
						tBox.tLocation.iY = obstacles[i].iHight + obstacles[i].iGap ;
						tBox.tSize.iWidth = 26;
						tBox.tSize.iHeight= 203-tBox.tLocation.iY;
						
						s_child_tilePipe.tRegion.tSize.iHeight = tBox.tSize.iHeight;
						arm_2d_rgb16_tile_copy_with_colour_masking( &s_child_tilePipe, 
														ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_COPY);
						
						
				}
		}while(0);
		
		
		//===ice block==============
		do{
				for(uint8_t i = 0; i < 2; i++){
						tBox.tLocation.iX = ice_block_iY[i].iX - layer_1_iX;
						#if DISAPPEAR
						if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){												
								if((tBox.tLocation.iX < - 40) || (tBox.tLocation.iX >= 240)){
										continue;
								}
								
						}
						#endif
						tBox.tSize.iWidth = 40;
						if(tBox.tLocation.iX < -tBox.tSize.iWidth){
								ice_block_iY[i].iX += 196 * 2;
								continue;
						}
						tBox.tLocation.iY = ice_block_iY[i].iY ;
						
						tBox.tSize.iHeight= 30;	//c_tileIce
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileIce, 
																ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_COPY);
						
				}
				
				if(bIsNewFrame){
						for(uint8_t j = 0; j < 2; j++){
								ice_block_iY_up_down(j,layer_1_iX);
						}		
				}
		}while(0);				
		
		///////people//////////==============/////////////////////==========
		#if DISAPPEAR
		if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){	
				if(bIsNewFrame){
						sPeopleRun += 1;								
				}
		}
		#endif
		do{
				static uint8_t num = 0;
				
				tBox.tLocation.iX = 20 + sPeopleRun;	
				tBox.tLocation.iY = 40 - tplay_game_speed_X_Y.iY - (sPeopleRun>>1);
				if((num & 0x03) < 2){
						tBox.tSize.iWidth = 26;
						tBox.tSize.iHeight= 45;							
						
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople1, 
														ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_COPY);											
				}else{
				
						tBox.tSize.iWidth = 30;
						tBox.tSize.iHeight= 54;							
						
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople2, 
																ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_COPY);
				}
				num++;
		}while(0);
		
		if(ys_play_flag){
				if(bIsNewFrame){
						tplay_game_speed_X_Y.iX += 2;
				}
		}
		#if DISAPPEAR
		extern const arm_2d_tile_t c_tileArm2D;
		if(sPeopleRun > 120){
			static uint8_t alpha = 250;
			static uint8_t alpha2 = 255;
				//sPeopleRun = 231;
				//arm_2d_rgb16_fill_colour(ptTile, NULL, BACKGROUND_COLOR);
				if(sPeopleRun >240){
						sPeopleRun = 240;
				}
				tBox.tLocation.iX = 0;	
				tBox.tLocation.iY = 0;
				tBox.tSize.iWidth = 2*(120 + sPeopleRun -240);
				tBox.tSize.iHeight= 240;	
				//arm_2d_rgb16_fill_colour(ptTile, &tBox, 0x0000);
				arm_2d_rgb565_fill_colour_with_alpha(   
								ptTile, 
								&tBox, 
								(arm_2d_color_rgb565_t){0x0000}, 
								alpha2);
								
				if(sPeopleRun >=240){
						tBox.tLocation.iX = 63;	
						tBox.tLocation.iY = 80;
						tBox.tSize.iWidth = 114;
						tBox.tSize.iHeight= 55;	
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileArm2D, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
						if(alpha >= 20){
								arm_2d_rgb565_fill_colour_with_alpha(   
										ptTile, 
										&tBox, 
										(arm_2d_color_rgb565_t){0x0000}, 
										alpha);
						
								
								alpha-=2;
						}else{
								alpha2=210;
						}
								
				}
				return;
		}
		#endif
		lcd_text_location( 28, 37);
		lcd_printf( "%d",tplay_game_speed_X_Y.iX/10);					
}

//==================================================

const int8_t sin_100[]={0,17,34,50,64,77,87,94,98,100,98,94,87,77,64,50,34,17,0,-17,-34,-50,-64,-77,-87,-94,-98,-100,-98,-94,-87,-77,-64,-50,-34,-17,0};
int8_t my_sin100(uint16_t angle){
		if(angle > 360){
				angle = angle%360;
		}
   
		return sin_100[angle/10];
		
}

void ice_block_iY_up_down(uint8_t i,int16_t iX_x){
		int16_t iX;
		iX = ice_block_iY[i].iX - iX_x;
		if((iX > -40) &&(iX < 240)){
				ice_block_iY[i].iY = my_sin100(ice_block_iY[i].angle)*86/100 +86;
				ice_block_iY[i].time++;
				if((ice_block_iY[i].time & 0x3) == 1){
						ice_block_iY[i].angle += 10;
				}
				
		}
}
void flying(uint8_t key){
		static enum{
					FLY_INIT = 0,					
					FLY_DOWN,					
					FLY_UP,
		 }e_fly_mod = FLY_INIT;
		static uint8_t number = 0;
		switch(e_fly_mod){
				case FLY_INIT:
						number = 0;
						e_fly_mod = FLY_DOWN;
				//break;
				case FLY_DOWN:
						number++;
						if((number % 5) == 0){
								tplay_game_speed_X_Y.iY -= 3 * 2;//MOVING_SPEED_iX;
								if(tplay_game_speed_X_Y.iY < -150){
										tplay_game_speed_X_Y.iY = -150;
								}
						}else if((number % 5) == 2){
								tplay_game_speed_X_Y.iY += 2;//MOVING_SPEED_iX;
						}
						if(key){
								e_fly_mod = FLY_UP;
								number = 10;
						}
				break;
				case FLY_UP:
						if(number % 2){
								tplay_game_speed_X_Y.iY += 4 * 1;//MOVING_SPEED_iX;
								if(tplay_game_speed_X_Y.iY > 50){
										tplay_game_speed_X_Y.iY = 50;
								}
						}else{
								tplay_game_speed_X_Y.iY -= 1;//MOVING_SPEED_iX;
						}
						number--;
						if(number == 0){
								e_fly_mod = FLY_INIT;
						}
				break;
		}
}


																
uint8_t ys_hit_against_inspect(){
		arm_2d_region_t  ptRegionIn0 = {.tLocation={.iX =20,.iY =40},.tSize={.iWidth = 26,.iHeight= 45}};
		arm_2d_region_t  ptRegionIn1 = {.tLocation={.iX =0,.iY =0},.tSize={.iWidth = 26,.iHeight= 0}};
		arm_2d_region_t  ptRegionOut;
		#if DISAPPEAR
		if(tplay_game_speed_X_Y.iX > (DISAPPEAR_TIME)){
				return 0;
		}
		#endif	
		ptRegionIn0.tLocation.iY = 40 - tplay_game_speed_X_Y.iY;
					
		for(uint8_t i = 0; i < 2; i++){
				
				ptRegionIn1.tLocation.iX = obstacles[i].iX - layer_1_iX;
				ptRegionIn1.tLocation.iY = 0;
				ptRegionIn1.tSize.iWidth = 26;
				ptRegionIn1.tSize.iHeight = obstacles[i].iHight;
				if(arm_2d_region_intersect(&ptRegionIn0,&ptRegionIn1,&ptRegionOut)){
						if(ptRegionOut.tSize.iHeight * ptRegionOut.tSize.iWidth > 100){
								return 1;
						}
				}
								
				//ptRegionIn1.tLocation.iX = obstacles[i].iX - tplay_game_speed_X_Y.iX;
				//region.tSize.iWidth = 26;
				ptRegionIn1.tLocation.iY = obstacles[i].iHight + obstacles[i].iGap;				
				ptRegionIn1.tSize.iHeight = 240-ptRegionIn1.tLocation.iY;
				if(arm_2d_region_intersect(&ptRegionIn0,&ptRegionIn1,&ptRegionOut)){
						if(ptRegionOut.tSize.iHeight * ptRegionOut.tSize.iWidth > 100){
								return 1;
						}
				}								
		}
		//撞冰块
		#if 1
		for(uint8_t i = 0; i < 2; i++){
				ptRegionIn1.tLocation.iX = ice_block_iY[i].iX - layer_1_iX;
				ptRegionIn1.tLocation.iY = ice_block_iY[i].iY ;
				ptRegionIn1.tSize.iWidth = 40;
				ptRegionIn1.tSize.iHeight = 30;
				if(arm_2d_region_intersect(&ptRegionIn0,&ptRegionIn1,&ptRegionOut)){
						if(ptRegionOut.tSize.iHeight * ptRegionOut.tSize.iWidth > (26*20)){
								tplay_game_speed_X_Y.iY = -150;
								return 2;
						}
				}	
		}
		#endif
	
		return 0;
}

void ys_play_game_init(){
		obstacles[1].iX = JULI+296;
		obstacles[0].iX = JULI+100;
		ice_block_iY[1].iX = obstacles[1].iX + 65+26+ 196*ICE_NUM;
		ice_block_iY[0].iX = obstacles[0].iX + 65+26+ 196*ICE_NUM;
	
		tplay_game_speed_X_Y.iX = 0;
		tplay_game_speed_X_Y.iY = -80;
		layer_1_iX=0;
}

uint8_t ys_autokey(){
		int16_t iX,iY;
		static uint8_t flag = 0;
		if(tplay_game_speed_X_Y.iX < JULI){
				iY = 40 - tplay_game_speed_X_Y.iY ;
				if(iY > (obstacles[0].iHight + obstacles[0].iGap-45)){
						//flag++;
						return 1;
				}
				
				return 0;
		}
		#if DISAPPEAR
		if(tplay_game_speed_X_Y.iX > (DISAPPEAR_TIME+40)){
				return 0;
		}
		#endif
		for(uint8_t i=0; i < 2; i++){
			
				iX = obstacles[i].iX - layer_1_iX;
				if((iX < (46+100)) && (iX > (46+15))){
						iY = 40 - tplay_game_speed_X_Y.iY + 45;
						if((iY > (obstacles[i].iHight+obstacles[i].iGap-20)) && (flag == 0)){
								flag++;
								return 1;
						}
				}
		}
		if(flag){
				flag++;
				if(flag > 2){
						flag = 0;
				}
		}
		
		return 0;
}

void play_game_ys(){		
		uint8_t key = 0,stop_flag=0;	
		
		key = get_key();
		//if(ys_play_flag){
		//		key = ys_autokey();
		//}		
		
		if(ys_play_flag){
				flying(key);
				stop_flag = ys_hit_against_inspect();
				if(stop_flag){
						ys_play_flag = 0;
				}
		}else{
				if(key == DIRECTION_KEY_A){
						ys_play_game_init();
						ys_play_flag = 1;
				}
				if(key){
						//ys_play_flag = 1;
				}
		}
}



//=========old===================================
uint8_t ys_hit_against_inspect2(){   //=========old===================================
		arm_2d_location_t point = {46,0};
		arm_2d_region_t region = {.tLocation={.iX = 0,.iY = 0},
															.tSize= {.iWidth=26,.iHeight=0}};
		//point.iX = 56;
		for(uint8_t i = 0; i < 2; i++){
				point.iY = 40 - tplay_game_speed_X_Y.iY;
				region.tLocation.iX = obstacles[i].iX - tplay_game_speed_X_Y.iX;
				region.tLocation.iY = 0;
				//region.tSize.iWidth = 26;
				region.tSize.iHeight = obstacles[i].iHight;
				if(arm_2d_is_point_inside_region(&region,&point)){
						return 1;
				}
				
				point.iY = 40 - tplay_game_speed_X_Y.iY + 45;
				region.tLocation.iX = obstacles[i].iX - tplay_game_speed_X_Y.iX;
				region.tLocation.iY = obstacles[i].iHight + obstacles[i].iGap;
				//region.tSize.iWidth = 26;
				region.tSize.iHeight = 240-region.tLocation.iY;
				if(arm_2d_is_point_inside_region(&region,&point)){
						return 1;
				}
		}
		return 0;
}

void ice_block_iY_up_down2(uint8_t i,int16_t iX_x){
		int16_t iX;
		iX = ice_block_iY[i].iX - iX_x;
		if((iX > -40) &&(iX < 240)){
				if(ice_block_iY[i].flag <= 100){  //xia  jiang
						if((ice_block_iY[i].flag&0x3) == 0){
								ice_block_iY[i].iY+= 4;
								ice_block_iY[i].flag++;
						}else{
								ice_block_iY[i].flag++;
						}
					
						if(ice_block_iY[i].iY > (172)){
								//ice_block_iY[i].iY = 172 - (ice_block_iY[i].iY - 172);
								ice_block_iY[i].flag = 101;
						}
				}else if(ice_block_iY[i].flag <= 200){
						if(ice_block_iY[i].iY > (172)){
								ice_block_iY[i].iY = 172 - (ice_block_iY[i].iY - 172);
								ice_block_iY[i].flag++;
						}
						if((ice_block_iY[i].flag&0x3) == 1){
								ice_block_iY[i].iY-= 4;
								ice_block_iY[i].flag++;
						}else{
								ice_block_iY[i].flag++;
						}
						
						
						
						if(ice_block_iY[i].iY < 5){
								ice_block_iY[i].flag = 0;
						}
						
				}
		}
}

void paly_game_gui_refresh2(const arm_2d_tile_t *ptTile, bool bIsNewFrame){
		arm_2d_region_t tBox = {
        .tLocation = {0,0},
        .tSize = {240,240-90},
    };
		static uint8_t sPeopleRun = 0;
		
			
		static uint8_t num = 0;
		
		
		
		
//===========================

		

//=========================		
		
		arm_2d_rgb16_fill_colour(ptTile, &tBox, BACKGROUND_COLOR);
		//arm_2d_rgb16_fill_colour(ptTile, NULL, 0x0000);
		for(uint8_t y = 0; y < 4; y++){
				layer_t *ptItem = &layers[y];
				if(bIsNewFrame){
						if(ptItem->layer_level==1){
								if(ys_play_flag)
								ptItem->offect_iX += ptItem->speed_iX;
						}
						else if(((tplay_game_speed_X_Y.iX>>1) % ptItem->layer_level) == 1){
								if(ys_play_flag)
								ptItem->offect_iX += ptItem->speed_iX;
						}
				}
				
				for(uint8_t i = 0;i < ptItem->for_num; i++){
						uint8_t index = i;
						tBox.tLocation.iX = ptItem->ptLocation[i].iX - ptItem->offect_iX;
						if(tBox.tLocation.iX > 240){
								continue;
						}
						//if(ptItem->uflag.bIsRandom){
								index = ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums;
						//}//else{
								//index = i;
						//}
						tBox.tSize.iWidth = ptItem->ptTiles[index].tRegion.tSize.iWidth;
						if(tBox.tLocation.iX <= (-tBox.tSize.iWidth)){
								/*if(ptItem->uflag.bIsRandom){
										index = (i+ptItem->for_num-1)%ptItem->for_num;
										ptItem->ptRandom_tile_nums[i] = myrand()%(ptItem->tiles_nums*2-1);//layer_3_nums[i] = myrand()%5;
									
										ptItem->ptLocation[i].iX =  ptItem->ptTiles_iX_offect[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums] 
																								+  myrand()%20 
																								+ ptItem->ptLocation[index].iX 
																								+ ptItem->ptTiles[ptItem->ptRandom_tile_nums[index%ptItem->tiles_nums]].tRegion.tSize.iWidth;
										ptItem->ptLocation[i].iY =  myrand()%20 
																								+ ptItem->ptTiles_iY_offect[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums];		
								}else{
										index = (i+ptItem->for_num-1)%ptItem->for_num;
										ptItem->ptLocation[i].iX = ptItem->ptLocation[index].iX + ptItem->ptTiles[index].tRegion.tSize.iWidth;	
								}
								
								if(ptItem->uflag.bIsAlign_Bottom){
										if(ptItem->uflag.bIsRandom){
												ptItem->ptLocation[i].iY = ptItem->Align_Bottom_iY - ptItem->ptTiles[ptItem->ptRandom_tile_nums[i]%ptItem->tiles_nums].tRegion.tSize.iHeight;
										}else{
												ptItem->ptLocation[i].iY = ptItem->Align_Bottom_iY - ptItem->ptTiles[i].tRegion.tSize.iHeight;
										}
								}
								for(uint8_t x = 0; x < ptItem->for_num; x++){
										ptItem->ptLocation[x].iX -= ptItem->offect_iX;
								}
								ptItem->offect_iX = 0;
								*/
								continue;
						}
						
						tBox.tLocation.iY = ptItem->ptLocation[i].iY ;
						tBox.tSize.iHeight= ptItem->ptTiles[index].tRegion.tSize.iHeight; 
						arm_2d_rgb16_tile_copy_with_colour_masking(  &ptItem->ptTiles[index], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
						
				}
				if(y == 0){
						tBox.tLocation.iX = 0;		
						tBox.tLocation.iY = 0;		
						tBox.tSize.iWidth = 240;
						tBox.tSize.iHeight= 240-90;	
						//arm_2d_rgb16_fill_colour(ptTile, &tBox, BACKGROUND_COLOR);
						arm_2d_rgb565_fill_colour_with_alpha(   
								ptTile, 
								&tBox, 
								(arm_2d_color_rgb565_t){BACKGROUND_COLOR}, 
								68);
				}
				
		}
		
		//======1====================================================
		
		extern const arm_2d_tile_t c_tileWoodLeft;
		extern const arm_2d_tile_t c_tileWoodUp;
		extern const arm_2d_tile_t c_tileLeafDown;
		extern const arm_2d_tile_t c_tileLeaf;
		//c_tilePipe
		#define LEAFCOLOR 0x9587
		#define WOODCOLOR 0xa883
		if(((tplay_game_speed_X_Y.iX>>1) % 2) == 1){
				if(ys_play_flag && bIsNewFrame){
						layer_1_iX+=6;
				}
		}
		//static playgame_obstacle_t obstacles[2] = {{500+100,70,75,1},{500+276,41,95,1}};
	
		for(uint8_t i = 0; i < 2; i++){
				tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;	
				#if DISAPPEAR
				if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){												
						if((tBox.tLocation.iX < - 26) || (tBox.tLocation.iX >= 240)){
								continue;
						}
						
				}
				#endif
				
				tBox.tSize.iWidth = 26;
				if(tBox.tLocation.iX < - tBox.tSize.iWidth){
						obstacles[i].iX = obstacles[i].iX+196 * 2;
						obstacles[i].iHight = 37 + myrand()%43;
						obstacles[i].iGap = 75 +  myrand()%20;
						continue;
				}
				//tBox.tLocation.iY = 0;
				
				//tBox.tSize.iHeight= obstacles[i].iHight;
				//arm_2d_rgb16_fill_colour(ptTile, &tBox, LEAFCOLOR);
				
				//==leaf====
				//tBox.tLocation.iX = 160;
				//tBox.tLocation.iY = obstacles[i].iHight-37;
				tBox.tLocation.iY = 0;
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= obstacles[i].iHight;	
				
				static arm_2d_tile_t s_child_tilePipe = {
						.tRegion = {
							.tSize = {
								.iWidth = 26,
								.iHeight = 16,
							},
						},       
						.tInfo = {
								.bIsRoot = false,
								.bDerivedResource = true,
								.bHasEnforcedColour = true,
								.tColourInfo = {
										.chScheme = ARM_2D_COLOUR_RGB565,
								},
							},             
							.ptParent = (arm_2d_tile_t *)&c_tilePipe,
				};
				s_child_tilePipe.tRegion.tSize.iHeight = tBox.tSize.iHeight;
				arm_2d_rgb16_tile_copy_with_colour_masking( &s_child_tilePipe, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_Y_MIRROR);
				
				
				tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;		
				tBox.tLocation.iY = obstacles[i].iHight + obstacles[i].iGap ;
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= 203-tBox.tLocation.iY;
				s_child_tilePipe.tRegion.tSize.iHeight = tBox.tSize.iHeight;
				arm_2d_rgb16_tile_copy_with_colour_masking( &s_child_tilePipe, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				/*
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeafDown, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				for(uint8_t j=0; j < 4; j++){					
						if((j==0) &&(tBox.tLocation.iY > 13)){																
								//tBox.tLocation.iX = 160;
								tBox.tLocation.iY -= 13;
								tBox.tSize.iWidth = 13;
								tBox.tSize.iHeight= 16;	
								arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
																ptTile, 
														&tBox, 
														GLCD_COLOR_BLACK,
														ARM_2D_CP_MODE_X_MIRROR);
							
								tBox.tLocation.iX += 13;
								//tBox.tLocation.iY = 60-13;
								//tBox.tSize.iWidth = 13;
								//tBox.tSize.iHeight= 16;	
								arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
																				ptTile, 
																		&tBox, 
																		GLCD_COLOR_BLACK,
																		ARM_2D_CP_MODE_COPY);
						}else{
								if(tBox.tLocation.iY > 15){
										tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;	
										tBox.tLocation.iY -= 15;
										tBox.tSize.iWidth = 13;
										tBox.tSize.iHeight= 16;	
										arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
																		ptTile, 
																&tBox, 
																GLCD_COLOR_BLACK,
																ARM_2D_CP_MODE_X_MIRROR);
									
										tBox.tLocation.iX += 13;
										//tBox.tLocation.iY = 60-13;
										//tBox.tSize.iWidth = 13;
										//tBox.tSize.iHeight= 16;	
										arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
																				ptTile, 
																		&tBox, 
																		GLCD_COLOR_BLACK,
																		ARM_2D_CP_MODE_COPY);
								}else{
										break;
								}
						}
				}
				if(tBox.tLocation.iY > 2){
						tBox.tLocation.iX -= 1;
						if(tBox.tLocation.iX != (obstacles[i].iX - layer_1_iX+12)){
								tBox.tLocation.iX += 11;
						}
						tBox.tSize.iHeight= tBox.tLocation.iY;
						tBox.tLocation.iY = 0;
						tBox.tSize.iWidth = 2;				
						arm_2d_rgb16_fill_colour(ptTile, &tBox, LEAFCOLOR);
				}*/
				//==wood====
				/*
				tBox.tLocation.iX = obstacles[i].iX - layer_1_iX;		
				tBox.tLocation.iY = obstacles[i].iHight + obstacles[i].iGap +3;
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= 203-tBox.tLocation.iY;
				arm_2d_rgb16_fill_colour(ptTile, &tBox, WOODCOLOR);
				
				tBox.tLocation.iY -= 3;
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= 7;	
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileWoodUp, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				
				tBox.tLocation.iX += 1;
				tBox.tLocation.iY += 15;
				tBox.tSize.iWidth = 6;
				tBox.tSize.iHeight= 17;	
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileWoodLeft, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
				*/
		}
		
		//===ice block==============
		for(uint8_t i = 0; i < 2; i++){
				tBox.tLocation.iX = ice_block_iY[i].iX - layer_1_iX;
				#if DISAPPEAR
				if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){												
						if((tBox.tLocation.iX < - 40) || (tBox.tLocation.iX >= 240)){
								continue;
						}
						
				}
				#endif
				tBox.tSize.iWidth = 40;
				if(tBox.tLocation.iX < -tBox.tSize.iWidth){
						ice_block_iY[i].iX += 196 * 2;
						continue;
				}
				tBox.tLocation.iY = ice_block_iY[i].iY ;
				
				tBox.tSize.iHeight= 30;	//c_tileIce
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileIce, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				
		}
		
		if(bIsNewFrame){
				for(uint8_t j = 0; j < 2; j++){
						ice_block_iY_up_down(j,layer_1_iX);
				}		
		}
		
		///////people//////////==============/////////////////////==========
		#if DISAPPEAR
		if(tplay_game_speed_X_Y.iX > DISAPPEAR_TIME){	
				if(bIsNewFrame){
						sPeopleRun += 1;		
						
				}
		}
		#endif
		tBox.tLocation.iX = 20 + sPeopleRun;	
		tBox.tLocation.iY = 40 - tplay_game_speed_X_Y.iY - (sPeopleRun>>1);
		if((num & 0x03) < 2){
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= 45;							
				
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople1, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);											
		}else{
		
				tBox.tSize.iWidth = 30;
				tBox.tSize.iHeight= 54;							
				
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople2, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		}
		num++;
		
		if(ys_play_flag){
				if(bIsNewFrame){
						tplay_game_speed_X_Y.iX += 2;
				}
		}
		#if DISAPPEAR
		extern const arm_2d_tile_t c_tileArm2D;
		if(sPeopleRun > 120){
			static uint8_t alpha = 250;
			static uint8_t alpha2 = 255;
				//sPeopleRun = 231;
				//arm_2d_rgb16_fill_colour(ptTile, NULL, BACKGROUND_COLOR);
				if(sPeopleRun >240){
						sPeopleRun = 240;
				}
				tBox.tLocation.iX = 0;	
				tBox.tLocation.iY = 0;
				tBox.tSize.iWidth = 2*(120 + sPeopleRun -240);
				tBox.tSize.iHeight= 240;	
				//arm_2d_rgb16_fill_colour(ptTile, &tBox, 0x0000);
				arm_2d_rgb565_fill_colour_with_alpha(   
								ptTile, 
								&tBox, 
								(arm_2d_color_rgb565_t){0x0000}, 
								alpha2);
								
				if(sPeopleRun >=240){
						tBox.tLocation.iX = 63;	
						tBox.tLocation.iY = 80;
						tBox.tSize.iWidth = 114;
						tBox.tSize.iHeight= 55;	
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileArm2D, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
						if(alpha >= 20){
								arm_2d_rgb565_fill_colour_with_alpha(   
										ptTile, 
										&tBox, 
										(arm_2d_color_rgb565_t){0x0000}, 
										alpha);
						
								
								alpha-=2;
						}else{
								alpha2=210;
						}
								
				}
				return;
		}
		#endif
		//======4========================================================
		/*for(uint8_t i = 0; i < 3; i++){
				layer_t *ptItem = &layers[i];
				const arm_2d_tile_t *ptShowTile;
				if(((tplay_game_speed_X_Y.iX>>1) % ptItem->level) == 1){
						if(bIsNewFrame){
								ptItem->speed_iX+=ptItem->offect_speed;
						}
				}
				for(uint8_t j = 0;j < ptItem->random_num; j++){
						tBox.tLocation.iX = ptItem->ptLocation[j].iX - ptItem->speed_iX;
						if(ptItem->uflag.bIsRandom){
								tBox.tSize.iWidth = ptItem->ptTiles[ptItem->ptRandom_num[j]%ptItem->tiles_num].tRegion.tSize.iWidth;
						}else{
								tBox.tSize.iWidth = ptItem->ptTiles[j].tRegion.tSize.iWidth;
						}
						if(tBox.tLocation.iX > 240){
								continue;
						}
						if(tBox.tLocation.iX <= (-tBox.tSize.iWidth)){
								
								//ptItem->random_num
								if(ptItem->uflag.bIsRandom){
										uint8_t num = (j+ptItem->random_num-1)%ptItem->random_num;
										ptItem->ptRandom_num[j] = myrand()%(ptItem->tiles_num*2-1);//layer_3_nums[i] = myrand()%5;
									//layer_1_location_iX[i] = layer_1_location_iX[(i+7)%8] + c_tile11[layer_1_nums[(i+7)%8]%6].tRegion.tSize.iWidth + layer_1_location_add_iX[layer_1_nums[i]%6]+ myrand()%20;
										ptItem->ptLocation[j].iX =  ptItem->ptTiles_iX_offect[ptItem->ptRandom_num[j]%ptItem->tiles_num] 
																								+  myrand()%20 
																								+ ptItem->ptLocation[num].iX 
																								+ ptItem->ptTiles[ptItem->ptRandom_num[num%ptItem->tiles_num]].tRegion.tSize.iWidth;
										ptItem->ptLocation[j].iY =  myrand()%20 
																								+ ptItem->ptTiles_iY_offect[ptItem->ptRandom_num[j]%ptItem->tiles_num];		
										
								}else{
										uint8_t num = (j+ptItem->tiles_num-1)%ptItem->tiles_num;
										ptItem->ptLocation[j].iX = ptItem->ptLocation[num].iX + ptItem->ptTiles[num].tRegion.tSize.iWidth;							
								}																					
								for(uint8_t x = 0; x < ptItem->tiles_num; x++){
										ptItem->ptLocation[x].iX -= ptItem->speed_iX;
								}
								ptItem->speed_iX = 0;
								continue;
						}
						if(ptItem->uflag.bIsAlign_Bottom){
								if(ptItem->uflag.bIsRandom){
										tBox.tLocation.iY = ptItem->offect_iY - ptItem->ptTiles[ptItem->ptRandom_num[j]%ptItem->tiles_num].tRegion.tSize.iHeight;
								}else{
										tBox.tLocation.iY = ptItem->offect_iY - ptItem->ptTiles[j].tRegion.tSize.iHeight;
								}
						}else{
								tBox.tLocation.iY = ptItem->ptLocation[j].iY ;	
						}
						if(ptItem->uflag.bIsRandom){
								tBox.tSize.iHeight= ptItem->ptTiles[ptItem->ptRandom_num[j]%ptItem->tiles_num].tRegion.tSize.iHeight;
								ptShowTile =  &ptItem->ptTiles[ptItem->ptRandom_num[j]%ptItem->tiles_num];
						}else{								
								tBox.tSize.iHeight= ptItem->ptTiles[j].tRegion.tSize.iHeight; 
								ptShowTile = &ptItem->ptTiles[j];
						}
						
						arm_2d_rgb16_tile_copy_with_colour_masking( ptShowTile, 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				}
				
				if(i == 0){
						tBox.tLocation.iX = 0;		
						tBox.tLocation.iY = 0;		
						tBox.tSize.iWidth = 240;
						tBox.tSize.iHeight= 240-90;	
						//arm_2d_rgb16_fill_colour(ptTile, &tBox, BACKGROUND_COLOR);
						arm_2d_rgb565_fill_colour_with_alpha(   
								ptTile, 
								&tBox, 
								(arm_2d_color_rgb565_t){BACKGROUND_COLOR}, 
								138);
				}
		}*/
		/*
		if(((tplay_game_speed_X_Y.iX>>1) % 4) == 1){
				layer_3_iX++;
		}
		for(uint8_t i = 0; i < 3; i++){
				tBox.tLocation.iX = layer_3_location[i].iX - layer_3_iX;	
				tBox.tSize.iWidth = c_tile33[layer_3_nums[i]%3].tRegion.tSize.iWidth;
				if(tBox.tLocation.iX < -tBox.tSize.iWidth){
						layer_3_nums[i] = myrand()%5;
						layer_3_location[i].iX = 20 + myrand()%20 + layer_3_location[(i+2)%3].iX +  c_tile33[layer_3_nums[(i+2)%3]%3].tRegion.tSize.iWidth;
						layer_3_location[i].iY = layer_3_location_iY[layer_3_nums[i]%3] + myrand()%20;//layer_3_location_ix[layer_3_nums[i]] + myrand()%20;
						
						if(layer_3_location[i].iX < 290){
								layer_3_location[i].iX = 290;
						}
						for(uint8_t j = 0; j < 3; j++){
								layer_3_location[j].iX -= layer_3_iX;
						}
						layer_3_iX = 0;
						continue;
				}
				tBox.tLocation.iY = layer_3_location[i].iY;		
				//tBox.tSize.iWidth = c_tile33[layer_3_nums[i]%3].tRegion.tSize.iWidth;
				tBox.tSize.iHeight= c_tile33[layer_3_nums[i]%3].tRegion.tSize.iHeight;
				if(layer_3_nums[i] > 2){
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile33[layer_3_nums[i]%3], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);
				}else{
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile33[layer_3_nums[i]%3], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				}
		}*/
		/*
		tBox.tLocation.iX = 10;		
		tBox.tLocation.iY = 30;		
		tBox.tSize.iWidth = c_tile3301.tRegion.tSize.iWidth;
		tBox.tSize.iHeight= c_tile3301.tRegion.tSize.iHeight;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile3301, 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		
		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth +10;		
		tBox.tLocation.iY = 50;		
		tBox.tSize.iWidth = c_tile3303.tRegion.tSize.iWidth;
		tBox.tSize.iHeight= c_tile3303.tRegion.tSize.iHeight;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile3303, 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		*/										
		
		//======3========================================================
		
		/*
		if(((tplay_game_speed_X_Y.iX>>1) % 2) == 1){
				if(bIsNewFrame)
				layer_2_iX+=6;
		}
		
		for(uint8_t i = 0; i < 6; i++){
				tBox.tLocation.iX = layer_2_location[i] - layer_2_iX;
				if(tBox.tLocation.iX > 240){
						continue;
				}
				if(tBox.tLocation.iX <= (0-c_tile44[i].tRegion.tSize.iWidth)){
						layer_2_location[i] = layer_2_location[(i+5)%6]+c_tile44[(i+5)%6].tRegion.tSize.iWidth;
						for(uint8_t j = 0; j < 6; j++){
								layer_2_location[j] = layer_2_location[j] - layer_2_iX;
						}
						layer_2_iX = 0;						
						continue;
				}
				tBox.tLocation.iY = 202-c_tile44[i].tRegion.tSize.iHeight;		
				tBox.tSize.iWidth = c_tile44[i].tRegion.tSize.iWidth;
				tBox.tSize.iHeight= c_tile44[i].tRegion.tSize.iHeight;
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile44[i], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		}*/
		
		//lcd_text_location( 0, 0);
		//lcd_printf( "%d=%d=%d=%d=%d=%d",layer_2_location[0],layer_2_location[1],layer_2_location[2],layer_2_location[3],layer_2_location[4],layer_2_iX);
		
		//======2========================================================
		//if(((tplay_game_speed_X_Y.iX>>1) % 2) == 1){
		//		layer_1_iX+=4;
		//}
		
		/*tBox.tLocation.iX = 0;		
		tBox.tLocation.iY = 202;		
		tBox.tSize.iWidth = 50;
		tBox.tSize.iHeight= 38;							
		for(uint8_t i=0; i < 6; i++){
				tBox.tLocation.iX = i*50 - layer_1_iX;
				if(tBox.tLocation.iX > 240 ){
						continue;
				}
				if(tBox.tLocation.iX <= -50){
						layer_1_iX -= 50;
						//for(uint8_t j = 0; j < 8; j++){
								//layer_1_location_iX[j] -= 50;
						//}
						for(uint8_t j = 0; j < 2; j++){
								obstacles[j].iX -= 50;
								ice_block_iY[j].iX -= 50;
						}
						//continue;
				}
				tBox.tLocation.iX = i*50 - layer_1_iX;
				arm_2d_rgb16_tile_copy( &c_tile1101, 
												ptTile, 
												&tBox, 												
												ARM_2D_CP_MODE_COPY);//ARM_2D_CP_MODE_FILL
		}*/
		
		//////=======///////========///////////////////
		/*
		for(uint8_t i=0; i < 8; i++){
				tBox.tLocation.iX = layer_1_location_iX[i]  - layer_1_iX;	
				tBox.tSize.iWidth = c_tile11[layer_1_nums[i]%6].tRegion.tSize.iWidth;
				if(tBox.tLocation.iX > 240){
						continue;
				}
				if(tBox.tLocation.iX < -tBox.tSize.iWidth){
						layer_1_nums[i] = (myrand()+layer_1_iX)%12;
						layer_1_location_iX[i] = layer_1_location_iX[(i+7)%8] + c_tile11[layer_1_nums[(i+7)%8]%6].tRegion.tSize.iWidth + layer_1_location_add_iX[layer_1_nums[i]%6]+ myrand()%20;
				}
				tBox.tLocation.iY = 203 - c_tile11[layer_1_nums[i]%6].tRegion.tSize.iHeight;
				//tBox.tSize.iWidth = c_tile11[layer_1_nums[i]%6].tRegion.tSize.iWidth;
				tBox.tSize.iHeight= c_tile11[layer_1_nums[i]%6].tRegion.tSize.iHeight;	
				if(layer_1_nums[i] > 5){
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile11[layer_1_nums[i]%6], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);
				}else{
						arm_2d_rgb16_tile_copy_with_colour_masking( &c_tile11[layer_1_nums[i]%6], 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
				}
		}*/
		
		
		
		
		
		/*
		tBox.tLocation.iX = 160;		
		tBox.tLocation.iY = 143;
		tBox.tSize.iWidth = 26;
		tBox.tSize.iHeight= 203-143;
		arm_2d_rgb16_fill_colour(ptTile, &tBox, WOODCOLOR);
		
		//tBox.tLocation.iX = 160;		
		tBox.tLocation.iY = 140;
		tBox.tSize.iWidth = 26;
		tBox.tSize.iHeight= 7;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileWoodUp, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		tBox.tLocation.iX = 160+1;
		tBox.tLocation.iY = 140+15;
		tBox.tSize.iWidth = 6;
		tBox.tSize.iHeight= 17;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileWoodLeft, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		*/										
		//====shuye
		
		/*
		tBox.tLocation.iX = 160;
		tBox.tLocation.iY = 60;
		tBox.tSize.iWidth = 26;
		tBox.tSize.iHeight= 37;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeafDown, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		tBox.tLocation.iX = 160+13;
		tBox.tLocation.iY = 60-13;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		tBox.tLocation.iX = 160;
		tBox.tLocation.iY = 60-13;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);
												
		tBox.tLocation.iX = 160+13;
		tBox.tLocation.iY = 60-13-15;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		tBox.tLocation.iX = 160;
		tBox.tLocation.iY = 60-13-15;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);
												
		tBox.tLocation.iX = 160+13;
		tBox.tLocation.iY = 60-13-15-15;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		tBox.tLocation.iX = 160;
		tBox.tLocation.iY = 60-13-15-15;
		tBox.tSize.iWidth = 13;
		tBox.tSize.iHeight= 16;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileLeaf, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);
												
		tBox.tLocation.iX = 160+12;		
		tBox.tLocation.iY = 0;
		tBox.tSize.iWidth = 2;
		tBox.tSize.iHeight= 17;
		arm_2d_rgb16_fill_colour(ptTile, &tBox, LEAFCOLOR);
		*/
		
		/*
		//arm_2d_rgb16_fill_colour(ptTile, NULL, 0x0000);
		tBox.tLocation.iX = 25;		
		tBox.tLocation.iY = 25;		
		tBox.tSize.iWidth = 189;
		tBox.tSize.iHeight= 189;	
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBjyq2, 
												ptTile, 
												&tBox, 	
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		
		tBox.tSize.iWidth = 122;
		tBox.tSize.iHeight= 189;	
		//arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBjyq1, 
		//										ptTile, 
		//										&tBox, 	
		//										GLCD_COLOR_BLACK,
		//										ARM_2D_CP_MODE_COPY);
		//										
		//
		watch_hand_rotation(ptTile,  bIsNewFrame);
		return;
		*/
	
}

/*======================================================================================================================================
 *======================================================================================================================================
 *======================================================================================================================================
 */
extern const arm_2d_tile_t c_tileBg21;
extern const arm_2d_tile_t c_tileBg22;
extern const arm_2d_tile_t c_tileBg23;
extern const arm_2d_tile_t c_tileBg24;
extern const arm_2d_tile_t c_tileBg31;
extern const arm_2d_tile_t c_tileBg32;

void paly_game_gui_refresh123(const arm_2d_tile_t *ptTile, bool bIsNewFrame){
		arm_2d_region_t tBox = {
        .tLocation = {30,0},
        .tSize = {30, 30},
    };
		static uint8_t num = 0;
		
		
		arm_2d_rgb16_fill_colour(ptTile, NULL, GLCD_COLOR_NAVY);
		
		
		tBox.tLocation.iX = 60;		
		tBox.tLocation.iY = 150;
		if((num & 0x03) < 2){
				tBox.tSize.iWidth = 26;
				tBox.tSize.iHeight= 45;							
				
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople1, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		}else{
		
				tBox.tSize.iWidth = 30;
				tBox.tSize.iHeight= 54;							
				
				arm_2d_rgb16_tile_copy_with_colour_masking( &c_tilePeople2, 
														ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		}
		num++;
		
		
		//===============================
				
		tBox.tLocation.iY = 80;		
		tBox.tLocation.iX = 0;
		tBox.tSize.iWidth = 31;
		tBox.tSize.iHeight= 48;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg21, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
		
		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth;		
		tBox.tLocation.iY = 80+20;		
		tBox.tSize.iWidth = 58;
		tBox.tSize.iHeight= 29;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg24, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);	
		
		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth;		
		tBox.tLocation.iY = 80;		
		tBox.tSize.iWidth = 31;
		tBox.tSize.iHeight= 39;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg22, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);
												
		

		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth;		
		tBox.tLocation.iY = 80+20;		
		tBox.tSize.iWidth = 58;
		tBox.tSize.iHeight= 29;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg24, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);	
												
		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth;		
		tBox.tLocation.iY = 80;		
		tBox.tSize.iWidth = 28;
		tBox.tSize.iHeight= 57;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg23, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);		
												
		//==================================================================
		tBox.tLocation.iX = 0;		
		tBox.tLocation.iY = 10;		
		tBox.tSize.iWidth = 66;
		tBox.tSize.iHeight= 16;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg31, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);		
												
		tBox.tLocation.iX =  tBox.tLocation.iX + tBox.tSize.iWidth;			
		tBox.tLocation.iY = 30;		
		tBox.tSize.iWidth = 46;
		tBox.tSize.iHeight= 20;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg32, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);			

		tBox.tLocation.iX =  tBox.tLocation.iX + tBox.tSize.iWidth;			
		tBox.tLocation.iY = 30;		
		tBox.tSize.iWidth = 46;
		tBox.tSize.iHeight= 20;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg32, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_COPY);		
												
		tBox.tLocation.iX = tBox.tLocation.iX + tBox.tSize.iWidth;			
		tBox.tLocation.iY = 20;		
		tBox.tSize.iWidth = 66;
		tBox.tSize.iHeight= 16;									
		arm_2d_rgb16_tile_copy_with_colour_masking( &c_tileBg31, 
												ptTile, 
												&tBox, 
												GLCD_COLOR_BLACK,
												ARM_2D_CP_MODE_X_MIRROR);		
}

//===============
extern const arm_2d_tile_t c_tileBjyq2;
extern const arm_2d_tile_t c_tileBjyq1;

typedef struct {
    arm_2d_op_rotate_opacity_t tOP;
    const arm_2d_tile_t *ptTile;//source Tile
    float fAngle;//旋转角度
    float fAngleSpeed;//旋转速度
    arm_2d_location_t tCentre;//source Tile的圆心
    arm_2d_location_t *ptTargetCentre;//Target Tile的圆心
    arm_2d_region_t tRegion;//旋转区域
    uint8_t chOpacity;//透明度
} rotation_watch_hand_t;
static rotation_watch_hand_t s_tGears[] = {
  {
    //source Tile
    .ptTile = &c_tileBjyq1,
    //旋转速度
    .fAngleSpeed = 3.f,
    //source Tile的圆心
    .tCentre = {
        .iX = 95,
        .iY = 95,
    },
    //旋转区域    
    .tRegion = {
        .tLocation = {
            .iX = 25,
            .iY = 25,
        },
        .tSize = {
            .iWidth = 95,
            .iHeight = 189,
        },
    },
    #if 1  /*! a demo shows how to specifiy the centre of rotation on the target tile */
        .ptTargetCentre = (arm_2d_location_t []){
            {
                .iX = 119-1,
                .iY = 119,
            },
        },
    #endif
    //透明度
    .chOpacity = 105,
  },
};

void watch_hand_rotation(const arm_2d_tile_t *ptTile, bool bIsNewFrame)
{            
    static uint8_t flag = 0;
		/*! for each item (ptItem) inside array s_tGears */
    arm_foreach (rotation_watch_hand_t, s_tGears, ptItem) {
      //更新旋转角度 
      if (bIsNewFrame) {
        //角度要转换成弧度
				if(0==flag){
						ptItem->fAngle += ARM_2D_ANGLE(ptItem->fAngleSpeed);
				}else{
						ptItem->fAngle -= ARM_2D_ANGLE(ptItem->fAngleSpeed);
				}
				if(ptItem->fAngle >= ARM_2D_ANGLE(130)){
						flag = 1;
				}else if(ptItem->fAngle <= ARM_2D_ANGLE(10)){
						flag = 0;
				}
        //角度取模，防止超出范围
        ptItem->fAngle = fmodf(ptItem->fAngle,ARM_2D_ANGLE(360));            
      }
        
        if (255 == ptItem->chOpacity) {
            //旋转不加透明度        
            arm_2dp_rgb565_tile_rotation((arm_2d_op_rotate_t *)&(ptItem->tOP),
                ptItem->ptTile,     //!< source tile
                ptTile,             //!< target tile
                &(ptItem->tRegion), //!< target region
                ptItem->tCentre,    //!< center point
                ptItem->fAngle,     //!< rotation angle
                GLCD_COLOR_BLACK,   //!< masking colour
                ptItem->ptTargetCentre);
        } else {
            //旋转加透明度 
            arm_2dp_rgb565_tile_rotation_with_alpha(
                &(ptItem->tOP),
                ptItem->ptTile,     //!< source tile
                ptTile,             //!< target tile
                &(ptItem->tRegion), //!< target region
                ptItem->tCentre,    //!< center point
                ptItem->fAngle,     //!< rotation angle
                GLCD_COLOR_BLACK,//GLCD_COLOR_BLACK,   //!< masking colour
                ptItem->chOpacity,  //!< Opacity
                ptItem->ptTargetCentre);
        }
    }
		lcd_text_location( 15, 17);
		//lcd_printf( "=%d",s_tGears[0].fAngle/3.14*180*0.278+50);
		lcd_printf( "%.1f%%",s_tGears[0].fAngle/3.14*180*0.278+50);
}